package com.cards_game.simple_ddz.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.cards_game.simple_ddz.bean.PlayerBean;
import com.cards_game.simple_ddz.bean.SimpleDdzBean;
import com.cards_game.simple_ddz.component.SimpleDdzCardsUtils;

public class RoomBean implements Comparable<RoomBean> {

	/**
	 * 构造器权限为包权限，避免创建更多对象
	 */
	RoomBean() {
	}

	/*
	 * 房间id，唯一标识
	 */
	private int id;
	
	/**
	 * 剩余准备时间
	 */
	private volatile int surplusTime=0;
	
	private volatile GameProgressEnum gpe;
	/**
	 * 上家出牌下标
	 */
	private volatile int lastPlayerNum;
	/*
	 * 房间号
	 */
	private int roomNum;
	/*
	 * 玩家列表
	 */
	private Vector<PlayerBean> playerList = new Vector<PlayerBean>(3);
	//公共区域纸牌
	private List<SimpleDdzBean> commonCards=new ArrayList<>();
	//上家出牌
	private List<SimpleDdzBean> lastCards=new ArrayList<>();
	//原始纸牌
	private List<SimpleDdzBean> originalCards=new ArrayList<>();
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getRoomNum() {
		return roomNum;
	}

	public void setRoomNum(int roomNum) {
		this.roomNum = roomNum;
	}

	public Vector<PlayerBean> getPlayerList() {
		return playerList;
	}

	public List<SimpleDdzBean> getCommonCards() {
		return commonCards;
	}

	public List<SimpleDdzBean> getOriginalCards() {
		if(originalCards.isEmpty()){
			synchronized (originalCards) {
				if(originalCards.isEmpty()){
					originalCards=SimpleDdzCardsUtils.getSimpleDdzCards();
				}
			}
		}
		return originalCards;
	}

	public int getSurplusTime() {
		return surplusTime;
	}

	public void setSurplusTime(int surplusTime) {
		this.surplusTime = surplusTime;
	}

	public int getLastPlayerNum() {
		return lastPlayerNum;
	}

	public void setLastPlayerNum(int lastPlayerNum) {
		this.lastPlayerNum = lastPlayerNum;
	}

	public List<SimpleDdzBean> getLastCards() {
		return lastCards;
	}

	public void setLastCards(List<SimpleDdzBean> lastCards) {
		this.lastCards = lastCards;
	}
	
	public void setCommonCards(List<SimpleDdzBean> commonCards) {
		this.commonCards = commonCards;
	}
	
	public GameProgressEnum getGpe() {
		return gpe;
	}

	public void setGpe(GameProgressEnum gpe) {
		this.gpe = gpe;
	}

	/**
	 * 重写房间bean的compareTo方法，
	 * 升序排列， 如果要添加的元素，容器自动调用该方法，与容器中的元素进行对比
	 * this为要插入的元素，o为容器中的元素
	 * 等待人员最多的房间优先匹配，房间号较小的房间优先匹配
	 * @param o
	 * @return
	 */
	@Override
	public int compareTo(RoomBean o) {
		int res = this.getPlayerList().size() - o.getPlayerList().size();
		if (res == 0) {
			res = o.getId()-this.getId();
		}
		return res;
	}

	@Override
	public String toString() {
		return "RoomBean [id=" + id + ", roomNum=" + roomNum + ", playerList=" + playerList + "]";
	}

}
